#!/sbin/openrc-run

pidfile=${pidfile:-/run/spamd.pid}
command=/usr/sbin/spamd
command_args="${command_args:--m 5 -c -H}"
extra_started_commands="reload"

depend() {
	need net
	before mta
	use logger
}

_legacy() {
	[ -n "$PIDFILE" ] && pidfile=$PIDFILE
	[ -n "$SPAMD_OPTS" ] && command_args=$SPAMD_OPTS
}

start_pre() {
	_legacy
	required_dirs="/var/lib/spamassassin/3.004001"
	if [ ! -d $required_dirs ]; then
		ebegin "Downloading rules"
		/usr/bin/sa-update
		eend $?
	fi
	command_args="-d -r $pidfile $command_args"
}

reload() {
	ebegin "Reloading $SVCNAME"
	start-stop-daemon --signal=HUP --pidfile $pidfile
	eend
}
